<template>
  <div>
    <el-table
      :data="tabData"
      :height="$store.state.app.tableHeight"
      border
      style="width: 100%; font-size:12px"
    >
      <el-table-column
        label="授权品牌名"
        align="center"
      >
        <template slot-scope="scope">
          <span>{{ scope.row.brand_content.brand_name }}</span>
        </template>
      </el-table-column>
      <el-table-column
        prop="product_code_num"
        label="产品代码"
        align="center"
      />
      <el-table-column
        prop="brand_product_name"
        label="产品名称"
        align="center"
      />
      <el-table-column
        prop="gg"
        label="规格"
        align="center"
      />
      <el-table-column
        prop="pany"
        label="单位"
        align="center"
      />
      <el-table-column
        prop="price"
        label="产品统一售价"
        align="center"
      />
      <el-table-column label="操作" align="center">
        <template slot-scope="scope">
          <el-button type="text" size="mini" @click="check(scope.row)">查看</el-button>
          <el-button type="text" size="mini" @click="handleCheck(scope.row)">修改</el-button>
          <el-button v-if="scope.row.status === '2'" type="text" size="mini" @click="upDown(scope.row)">上架</el-button>
          <el-button v-if="scope.row.status === '1'" type="text" size="mini" @click="upDown(scope.row)">下架</el-button>
          <del-comfirn :title="`是否确认删除名称为“ ${scope.row.brand_product_name} ”的产品？`" button-text="删除" @onConfirm="delProductInfo(scope.row)" />
        </template>
      </el-table-column>
    </el-table>
    <product-info ref="resetComp" operation-type="2" @reloadFun="reloadFun" />
  </div>
</template>

<script>
import delComfirn from '@/components/DelConfirm'
import { operationBrandProduct } from '@/api/brand'
import productInfo from './product-info'
export default {
  components: {
    delComfirn,
    productInfo
  },
  props: {
    tabData: {
      type: Array,
      default() {
        return []
      }
    }
  },
  data() {
    return {
    }
  },
  methods: {
    upDown(row) {
      this.$confirm(`此操作将[ ${row.status === '1' ? '下架' : '上架'} ]产品 [ ${row.brand_product_name} ] , 是否继续?`, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        const data = {
          type: 3,
          id: row.id,
          status: row.status === '1' ? '2' : '1'
        }
        operationBrandProduct(data).then(res => {
          if (res.code === 200) {
            this.$message.success(row.status === '1' ? '品牌产品已成功下架！' : '品牌产品已成功上架！')
            this.$emit('reloadFun')
          }
        })
      }).catch(() => {

      })
    },
    delProductInfo(row) {
      console.log(row)
      const data = {
        type: 3,
        id: row.id,
        status: 0
      }
      operationBrandProduct(data).then(res => {
        console.log(res)
        if (res.code === 200) {
          this.$message.success('删除成功！')
          this.$emit('reloadFun')
        }
      })
    },
    handleCheck(row) {
      this.$refs.resetComp.dialogFormVisible = true
      this.$refs.resetComp.form = JSON.parse(JSON.stringify(row))
      this.$refs.resetComp.isDisable = false
    },
    reloadFun() {
      this.$emit('reloadFun')
    },
    check(row) {
      this.$refs.resetComp.dialogFormVisible = true
      this.$refs.resetComp.form = JSON.parse(JSON.stringify(row))
      this.$refs.resetComp.isDisable = true
    }
  }
}
</script>

<style lang="sass" scoped>

</style>
